<template>
  <div class="page">
    <div class="searchline">
      <el-input
        placeholder="公司名称"
        v-model="search.name"
        size="medium"
        style="width: 200px; margin-left: 12px"
      ></el-input>
      <el-input
        placeholder="地址"
        size="medium"
        v-model="search.address"
        style="width: 200px; margin-left: 12px"
      ></el-input>
      <el-select
        placeholder="行业"
        v-model="search.industry"
        size="medium"
        style="width: 200px; margin-left: 12px"
      >
        <el-option-group
          v-for="group in options"
          :key="group.label"
          :label="group.label"
        >
          <el-option
            v-for="item in group.options"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-option-group>
      </el-select>
      <el-date-picker
        placeholder="注册年份"
        v-model="search.year"
        type="year"
        size="medium"
        style="width: 200px; margin-left: 12px"
        value-format="yyyy"
      >
      </el-date-picker>
      <el-button
        style="margin-left: 12px"
        size="medium"
        type="primary"
        @click="searchFromList(search)"
        >筛选</el-button
      >
      <el-button size="medium" type="info" @click="reSet()">重置</el-button>
    </div>
    <div class="flexBox">
      <el-card
        v-for="(item, index) in list"
        :key="index"
        shadow="always"
        class="box"
        @click.native="openDetail(item)"
      >
        <div class="card-info">
          <!-- <el-avatar shape="square" :size="50" :src="imgurl[0]"></el-avatar> -->
          <img
            style="width: 50px; height: 50px"
            src="../../../assets/img/company.png"
          />
          <div class="cart-text">
            <span
              style="
                font-weight: bold;
                font-size: 16px;
                color: rgb(65, 151, 46);
              "
              >{{ item.name }}</span
            ><br />
            {{ item.industry }}<br />
            {{ item.address }}<br />
            {{ item.year }}年成立<br />
          </div>
        </div>
        <el-divider class="line"></el-divider>
        <div class="card-info">公司简介：{{ item.introduction }}</div>
      </el-card>
    </div>
    <!-- 信息弹窗 -->
    <el-dialog
      title="企业信息"
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose"
    >
      <div class="dialogblock-info">
        <div class="title">{{ dialogItem.name }}</div>
        <div class="infoline">公司行业：{{ dialogItem.industry }}</div>
        <div class="infoline">公司地址：{{ dialogItem.address }}</div>
        <div class="infoline">注册年份：{{ dialogItem.year }}</div>
        <div class="infoline">注册资金：{{ dialogItem.capital }}</div>
        <div class="infoline">公司人数：{{ dialogItem.people }}</div>
        <div class="infoline">人才偏好：{{ dialogItem.like }}</div>
        <div class="infoline">公司简介：{{ dialogItem.introduction }}</div>
        <div class="infoline">入驻时间：{{ dialogItem.created_date }}</div>
        <div class="infoline">更新时间：{{ dialogItem.updated_date }}</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="dialogVisible = false">关闭</el-button>
        <el-button size="medium" type="primary" @click="goToPage(dialogItem)"
          >查看该公司职位</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { allCompany } from "@/api/company";
import { industryOption } from "@/util/selectOption";
import { dateFormat } from "@/util/common";

export default {
  data() {
    return {
      dialogVisible: false,
      dialogItem: {},
      search: {
        name: "",
        address: "",
        industry: "",
        year: "",
      },
      options: industryOption,
      value: "",
      list: [],
      initlist: [],
    };
  },
  mounted() {
    this.getAllCompany();
  },
  methods: {
    getAllCompany() {
      allCompany().then((res) => {
        if (res.code == 200) {
          this.initlist = res.data.Companys.map((item) => {
            item.created_date = dateFormat(
              "YYYY-mm-dd HH:MM",
              new Date(item.created_date)
            );
            item.updated_date = dateFormat(
              "YYYY-mm-dd HH:MM",
              new Date(item.updated_date)
            );
            return item;
          });
          this.list = this.initlist;
        }
      });
    },
    searchFromList(search) {
      const { name, address, industry, year } = search;
      this.list = this.initlist.filter((item) => {
        return (
          item.name.indexOf(name) !== -1 &&
          item.address.indexOf(address) !== -1 &&
          item.industry.indexOf(industry) !== -1 &&
          item.year.indexOf(year) !== -1
        );
      });
    },
    reSet() {
      this.search = {
        name: "",
        address: "",
        industry: "",
        year: "",
      };
      this.list = this.initlist;
    },
    openDetail(item) {
      this.dialogItem = { ...item };
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
      this.dialogItem = {};
    },
    goToPage(dialogItem) {
      const { name } = dialogItem;
      this.$router.push({
        path: "/jobCenter",
        query: {
          CompanyName: name,
        },
      });
    },
  },
};
</script>

<style scoped>
.page {
  /* height: 100vh; */
  /* flex-direction: row;
  width: 100%;
  justify-content: center; */
  /* text-align: center; */
}
.flexBox {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
.box {
  height: 180px;
  width: 260px;
  margin: 20px 0 0 20px;
  border-radius: 8px;
  cursor: pointer;
}
.searchline {
  margin-top: 20px;
  display: flex;
  justify-content: left;
  margin-left: 10px;
}
.card-info {
  display: flex;
  font-size: 12px;
  width: fit-content;
  /* justify-content: space-between; */
}
.line {
  margin: 10px 0 !important;
}
.card-info .cart-text {
  font-size: 12px;
  width: 140px;
  margin-left: 20px;
}

.dialogblock-info {
  width: 100%;
  height: 60vh;
  overflow-y: auto;
}
.dialogblock-info .infoline {
  margin: 10px 0;
  font-size: 18px;
}
.dialogblock-info .title {
  margin: 15px 0;
  font-size: 24px;
  color: rgb(65, 151, 46);
  font-weight: bold;
}
</style>